<?php

namespace App\Admin\Controllers;

use App\Models\Goods;
use App\Models\Log;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class GoodsController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '商品';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Goods);
        $grid->column('goods_id', __('Goods id'));
        $grid->column('main_image_url', __('商品主图'))->gallery(['width' => 50, 'height' => 50]);
        $grid->column('name', __('Name'));
        $grid->column('created_at', __('Created at'));
        $grid->column('updated_at', __('Updated at'));
        $grid->column('deleted_at', __('Deleted at'));
        $grid->column('status', __('Status'))->display(function ($status){
            if($status ==1){
                return '开启';
            }else{
                return '下架';
            }
        });
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Goods::findOrFail($id));

        $show->field('goods_id', __('Goods id'));
        $show->field('name', __('Name'));
        $show->field('main_image_url', __('Main image url'));
        $show->field('sku', __('Sku'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));
        $show->field('deleted_at', __('Deleted at'));
        $show->field('status', __('Status'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Goods);

        $form->text('name', __('商品名称'));
        $form->image('main_image_url', __('商品主图'));
        $form->sku('sku','选择规格');
        $form->UEditor('content','商品详情');
        $form->switch('status', __('Status'))->default(1);

        return $form;
    }


}
